package com.dormitory.dormitorymanagement.mapper;


import com.dormitory.dormitorymanagement.pojo.DormRepair;
import com.dormitory.dormitorymanagement.pojo.DormitoryAdmin;
import com.dormitory.dormitorymanagement.pojo.Notice;
import com.dormitory.dormitorymanagement.pojo.StudentEvaluations;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface AdminMapper {





    /**
     *  根据用户名查询管理员
     * @param username
     * @return
     */
    @Select("select * from dormitory.dormitory_admin where staff_id = #{username}")
    DormitoryAdmin findByStaffId(String username);


    /***
     *  查询所有报修单
     * @param startDate
     * @param endDate
     * @param dormitory
     * @return
     */
    List<DormRepair> repairList(LocalDateTime startDate, LocalDateTime endDate, String dormitory,String adminId);

    /**
     *  修改报修单状态
     * @param repairId
     * @param status
     */
    @Update("update dormitory.dorm_repair set repair_status = #{status} where id = #{repairId}")
    void updateRepairStatus(Integer repairId, String status);


    @Insert( "insert into dormitory.notice(title, content, publish_time, staff_id, staff_name, create_time, update_time, building_name) values (#{title},#{content},#{publishTime},#{staffId},#{staffName},#{createTime},#{updateTime},#{buildingName})")
    void notice(Notice notice);

    /***
     * 根据id查询管理员
     * @param targetId
     * @return
     */
    @Select( "select * from dormitory.dormitory_admin where id = #{targetId}")
    DormitoryAdmin findById(String targetId);


    /**
     * 获取学生的评价
     * @param studentId
     * @return
     */
    @Select( "select * from dormitory.student_evaluations where target_id = #{studentId} and target_role = 'dorm'")
    List<StudentEvaluations> getStudentClassmateEvaluations(String studentId);

    /**
     *  注册
     * @param dormAdmin
     */
    @Insert( "insert into dormitory.dormitory_admin(staff_id, username, password, building_responsible, name,  create_time, update_time) values (#{staffId},#{username},#{password},#{buildingResponsible},#{name},#{createTime},#{updateTime})")
    void adminRedister(DormitoryAdmin dormAdmin);
}
